package com.pearl.jacksoncore.demo.databind.module;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.util.JacksonFeatureSet;
import com.fasterxml.jackson.core.util.VersionUtil;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.deser.ValueInstantiators;
import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.introspect.AnnotatedClassResolver;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.module.SimpleDeserializers;
import com.fasterxml.jackson.databind.module.SimpleKeyDeserializers;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.module.SimpleSerializers;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.PackageVersion;
import com.fasterxml.jackson.datatype.jsr310.deser.*;
import com.fasterxml.jackson.datatype.jsr310.deser.key.*;
import com.fasterxml.jackson.datatype.jsr310.ser.*;
import com.fasterxml.jackson.datatype.jsr310.ser.key.ZonedDateTimeKeySerializer;

import java.time.*;
import java.util.Iterator;

/**
 * @author TD
 * @version 1.0
 * @date 2024/4/7
 */
public class MyModule extends SimpleModule {

    private static final long serialVersionUID = 1L;

    public static final Version VERSION = VersionUtil.parseVersion("1.0.0", "com.pearl", "jackson-datatype-my");


    public MyModule() {
        super(VERSION);
    }
    public void setupModule(Module.SetupContext context) {
        // 必须调用父类的
        super.setupModule(context);

        // 添加序列化器
        SimpleDeserializers desers = new SimpleDeserializers();
        desers.addDeserializer(ZoneOffset.class, JSR310StringParsableDeserializer.ZONE_OFFSET);
        context.addDeserializers(desers);

        // 添加反序列化器
        SimpleSerializers sers = new SimpleSerializers();
        sers.addSerializer(ZoneOffset.class, new ToStringSerializer(ZoneOffset.class));
        context.addSerializers(sers);
    }
}
